package display3D.objet3D
{
	import alternativa.engine3d.core.Clipping;
	import alternativa.engine3d.core.MipMapping;
	import alternativa.engine3d.core.Object3DContainer;
	import alternativa.engine3d.core.Sorting;
	import alternativa.engine3d.core.Vertex;
	import alternativa.engine3d.materials.FillMaterial;
	import alternativa.engine3d.materials.TextureMaterial;
	import alternativa.engine3d.objects.Mesh;
	import display3D.embed.Texture;

	/**
	 * Classe représentant le plafond de la salle 3D
	 * @author Arnaud
	 */
	public class Roof extends Floor
	{
		
		/**
		 * Constructeur
		 * @param x Coordonnée x du point du milieu
		 * @param y Coordonnée y du point du milieu
		 * @param z Coordonnée z du point du milieu
		 * @param distance Distance entre les deux point de la salle les plus éloignés
		 */
		public function Roof(x:*,y:*,z:*,distance:*)
		{
			super(x,y,z,distance);
		}
		
		/**
		 * Dessine le plafond sur la scene
		 * @param scene Conteneur de notre salle3D
		 */
		public override function draw(scene:Object3DContainer): void
		{
			
			var texture:TextureMaterial = new TextureMaterial(new (display3D.embed.Texture.EmbedTexturePlafond)().bitmapData, false, true, MipMapping.PER_PIXEL);
			texture.correctUV =true;
			
			var meshm:Mesh = new Mesh();
			var v1m:Vertex = meshm.addVertex(_x_milieu+_distance, _y_milieu+_distance,  _z_milieu, 0, 0, "v1m");
			var v4m:Vertex = meshm.addVertex(_x_milieu+_distance, _y_milieu-_distance,  _z_milieu, 0, 1, "v2m");
			var v2m:Vertex = meshm.addVertex(_x_milieu-_distance, _y_milieu+_distance,  _z_milieu, 1, 1, "v3m");
			var v3m:Vertex = meshm.addVertex(_x_milieu-_distance, _y_milieu-_distance,  _z_milieu, 1, 0, "v4m");
			meshm.addQuadFace(v4m,v3m,v2m,v1m, null,"faceMur1");
			meshm.addQuadFace(v1m,v2m,v3m,v4m, null,"faceMur2");
			meshm.calculateFacesNormals(true);
			meshm.clipping = Clipping.FACE_CLIPPING;
			meshm.sorting = Sorting.DYNAMIC_BSP;
			meshm.calculateBounds();
			meshm.setMaterialToAllFaces(texture);
			scene.addChild(meshm);
			_objet3D.push(meshm);
		}
	}
}